<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="产品id" prop="productId">
      <el-input v-model="dataForm.productId" placeholder="产品id"></el-input>
    </el-form-item>
    <el-form-item label="样品名称" prop="productName">
      <el-input v-model="dataForm.productName" placeholder="样品名称"></el-input>
    </el-form-item>
    <el-form-item label="生产者名称" prop="producerName">
      <el-input v-model="dataForm.producerName" placeholder="生产者名称"></el-input>
    </el-form-item>
    <el-form-item label="样品型号" prop="sampleType">
      <el-input v-model="dataForm.sampleType" placeholder="样品型号"></el-input>
    </el-form-item>
    <el-form-item label="注册地址" prop="registeredAddress">
      <el-input v-model="dataForm.registeredAddress" placeholder="注册地址"></el-input>
    </el-form-item>
    <el-form-item label="样品数量" prop="sampleNum">
      <el-input v-model="dataForm.sampleNum" placeholder="样品数量"></el-input>
    </el-form-item>
    <el-form-item label="生产厂名称" prop="manufactoryName">
      <el-input v-model="dataForm.manufactoryName" placeholder="生产厂名称"></el-input>
    </el-form-item>
    <el-form-item label="样品编号" prop="sampleBernum">
      <el-input v-model="dataForm.sampleBernum" placeholder="样品编号"></el-input>
    </el-form-item>
    <el-form-item label="样品注册地址" prop="registeredAddressSample">
      <el-input v-model="dataForm.registeredAddressSample" placeholder="样品注册地址"></el-input>
    </el-form-item>
    <el-form-item label="样品生产日期" prop="productionDate">
      <el-input v-model="dataForm.productionDate" placeholder="样品生产日期"></el-input>
    </el-form-item>
    <el-form-item label="样品等级" prop="sampleGrade">
      <el-input v-model="dataForm.sampleGrade" placeholder="样品等级"></el-input>
    </el-form-item>
    <el-form-item label="样品取样方式" prop="sampleAcqMethod">
      <el-input v-model="dataForm.sampleAcqMethod" placeholder="样品取样方式"></el-input>
    </el-form-item>
    <el-form-item label="抽样基数" prop="samplingBasicNumber">
      <el-input v-model="dataForm.samplingBasicNumber" placeholder="抽样基数"></el-input>
    </el-form-item>
    <el-form-item label="抽样日期" prop="samplingBasicDate">
      <el-input v-model="dataForm.samplingBasicDate" placeholder="抽样日期"></el-input>
    </el-form-item>
    <el-form-item label="抽样地点" prop="samplingBasicPlace">
      <el-input v-model="dataForm.samplingBasicPlace" placeholder="抽样地点"></el-input>
    </el-form-item>
    <el-form-item label="到样时间" prop="arriveDate">
      <el-input v-model="dataForm.arriveDate" placeholder="到样时间"></el-input>
    </el-form-item>
    <el-form-item label="检验时间" prop="provingTime">
      <el-input v-model="dataForm.provingTime" placeholder="检验时间"></el-input>
    </el-form-item>
    <el-form-item label="检验地点" prop="checkGroundPoint">
      <el-input v-model="dataForm.checkGroundPoint" placeholder="检验地点"></el-input>
    </el-form-item>
    <el-form-item label="主要检测设备" prop="mainTestingEquipment">
      <el-input v-model="dataForm.mainTestingEquipment" placeholder="主要检测设备"></el-input>
    </el-form-item>
    <el-form-item label="检验依据" prop="checkAccording">
      <el-input v-model="dataForm.checkAccording" placeholder="检验依据"></el-input>
    </el-form-item>
    <el-form-item label="检验结论" prop="checkConclusion">
      <el-input v-model="dataForm.checkConclusion" placeholder="检验结论"></el-input>
    </el-form-item>
    <el-form-item label="鉴定报告的签发日期" prop="issueDate">
      <el-input v-model="dataForm.issueDate" placeholder="鉴定报告的签发日期"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    <el-form-item label="报告状态" prop="reprotStatus">
      <el-input v-model="dataForm.reprotStatus" placeholder="报告状态"></el-input>
    </el-form-item>
    <el-form-item label="批准人" prop="approver">
      <el-input v-model="dataForm.approver" placeholder="批准人"></el-input>
    </el-form-item>
    <el-form-item label="批准人意见" prop="approvalOpinion">
      <el-input v-model="dataForm.approvalOpinion" placeholder="批准人意见"></el-input>
    </el-form-item>
    <el-form-item label="审核人" prop="auditor">
      <el-input v-model="dataForm.auditor" placeholder="审核人"></el-input>
    </el-form-item>
    <el-form-item label="审核人意见" prop="auditOpinion">
      <el-input v-model="dataForm.auditOpinion" placeholder="审核人意见"></el-input>
    </el-form-item>
    <el-form-item label="审核日期" prop="dateOfApproval">
      <el-input v-model="dataForm.dateOfApproval" placeholder="审核日期"></el-input>
    </el-form-item>
    <el-form-item label="项目负责人" prop="projectLeader">
      <el-input v-model="dataForm.projectLeader" placeholder="项目负责人"></el-input>
    </el-form-item>
    <el-form-item label="项目负责人意见" prop="projectLeaderOpinion">
      <el-input v-model="dataForm.projectLeaderOpinion" placeholder="项目负责人意见"></el-input>
    </el-form-item>
    <el-form-item label="项目负责人填写日期" prop="projectLeaderDate">
      <el-input v-model="dataForm.projectLeaderDate" placeholder="项目负责人填写日期"></el-input>
    </el-form-item>
    <el-form-item label="样品图片(产品名称)" prop="pictureProductName">
      <el-input v-model="dataForm.pictureProductName" placeholder="样品图片(产品名称)"></el-input>
    </el-form-item>
    <el-form-item label="样品图片(产品型号)" prop="pictureModel">
      <el-input v-model="dataForm.pictureModel" placeholder="样品图片(产品型号)"></el-input>
    </el-form-item>
    <el-form-item label="备注信息" prop="remarks">
      <el-input v-model="dataForm.remarks" placeholder="备注信息"></el-input>
    </el-form-item>
    <el-form-item label="报告编写人" prop="reportWriter">
      <el-input v-model="dataForm.reportWriter" placeholder="报告编写人"></el-input>
    </el-form-item>
    <el-form-item label="报告编写日期" prop="reportDate">
      <el-input v-model="dataForm.reportDate" placeholder="报告编写日期"></el-input>
    </el-form-item>
    <el-form-item label="报告校核人" prop="reportChecker">
      <el-input v-model="dataForm.reportChecker" placeholder="报告校核人"></el-input>
    </el-form-item>
    <el-form-item label="报告校核意见" prop="reportCheckerOpinion">
      <el-input v-model="dataForm.reportCheckerOpinion" placeholder="报告校核意见"></el-input>
    </el-form-item>
    <el-form-item label="报告校核日期" prop="reportCheckerDate">
      <el-input v-model="dataForm.reportCheckerDate" placeholder="报告校核日期"></el-input>
    </el-form-item>
    <el-form-item label="报告路径" prop="reportPath">
      <el-input v-model="dataForm.reportPath" placeholder="报告路径"></el-input>
    </el-form-item>
    <el-form-item label="pdf路径" prop="pdfPath">
      <el-input v-model="dataForm.pdfPath" placeholder="pdf路径"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          productId: '',
          productName: '',
          producerName: '',
          sampleType: '',
          registeredAddress: '',
          sampleNum: '',
          manufactoryName: '',
          sampleBernum: '',
          registeredAddressSample: '',
          productionDate: '',
          sampleGrade: '',
          sampleAcqMethod: '',
          samplingBasicNumber: '',
          samplingBasicDate: '',
          samplingBasicPlace: '',
          arriveDate: '',
          provingTime: '',
          checkGroundPoint: '',
          mainTestingEquipment: '',
          checkAccording: '',
          checkConclusion: '',
          issueDate: '',
          remark: '',
          reprotStatus: '',
          approver: '',
          approvalOpinion: '',
          auditor: '',
          auditOpinion: '',
          dateOfApproval: '',
          projectLeader: '',
          projectLeaderOpinion: '',
          projectLeaderDate: '',
          pictureProductName: '',
          pictureModel: '',
          remarks: '',
          reportWriter: '',
          reportDate: '',
          reportChecker: '',
          reportCheckerOpinion: '',
          reportCheckerDate: '',
          reportPath: '',
          pdfPath: ''
        },
        dataRule: {
          productId: [
            { required: true, message: '产品id不能为空', trigger: 'blur' }
          ],
          productName: [
            { required: true, message: '样品名称不能为空', trigger: 'blur' }
          ],
          producerName: [
            { required: true, message: '生产者名称不能为空', trigger: 'blur' }
          ],
          sampleType: [
            { required: true, message: '样品型号不能为空', trigger: 'blur' }
          ],
          registeredAddress: [
            { required: true, message: '注册地址不能为空', trigger: 'blur' }
          ],
          sampleNum: [
            { required: true, message: '样品数量不能为空', trigger: 'blur' }
          ],
          manufactoryName: [
            { required: true, message: '生产厂名称不能为空', trigger: 'blur' }
          ],
          sampleBernum: [
            { required: true, message: '样品编号不能为空', trigger: 'blur' }
          ],
          registeredAddressSample: [
            { required: true, message: '样品注册地址不能为空', trigger: 'blur' }
          ],
          productionDate: [
            { required: true, message: '样品生产日期不能为空', trigger: 'blur' }
          ],
          sampleGrade: [
            { required: true, message: '样品等级不能为空', trigger: 'blur' }
          ],
          sampleAcqMethod: [
            { required: true, message: '样品取样方式不能为空', trigger: 'blur' }
          ],
          samplingBasicNumber: [
            { required: true, message: '抽样基数不能为空', trigger: 'blur' }
          ],
          samplingBasicDate: [
            { required: true, message: '抽样日期不能为空', trigger: 'blur' }
          ],
          samplingBasicPlace: [
            { required: true, message: '抽样地点不能为空', trigger: 'blur' }
          ],
          arriveDate: [
            { required: true, message: '到样时间不能为空', trigger: 'blur' }
          ],
          provingTime: [
            { required: true, message: '检验时间不能为空', trigger: 'blur' }
          ],
          checkGroundPoint: [
            { required: true, message: '检验地点不能为空', trigger: 'blur' }
          ],
          mainTestingEquipment: [
            { required: true, message: '主要检测设备不能为空', trigger: 'blur' }
          ],
          checkAccording: [
            { required: true, message: '检验依据不能为空', trigger: 'blur' }
          ],
          checkConclusion: [
            { required: true, message: '检验结论不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          reprotStatus: [
            { required: true, message: '报告状态不能为空', trigger: 'blur' }
          ],
          approver: [
            { required: true, message: '批准人不能为空', trigger: 'blur' }
          ],
          approvalOpinion: [
            { required: true, message: '批准人意见不能为空', trigger: 'blur' }
          ],
          auditor: [
            { required: true, message: '审核人不能为空', trigger: 'blur' }
          ],
          auditOpinion: [
            { required: true, message: '审核人意见不能为空', trigger: 'blur' }
          ],
          dateOfApproval: [
            { required: true, message: '审核日期不能为空', trigger: 'blur' }
          ],
          projectLeader: [
            { required: true, message: '项目负责人不能为空', trigger: 'blur' }
          ],
          projectLeaderOpinion: [
            { required: true, message: '项目负责人意见不能为空', trigger: 'blur' }
          ],
          projectLeaderDate: [
            { required: true, message: '项目负责人填写日期不能为空', trigger: 'blur' }
          ],
          pictureProductName: [
            { required: true, message: '样品图片(产品名称)不能为空', trigger: 'blur' }
          ],
          pictureModel: [
            { required: true, message: '样品图片(产品型号)不能为空', trigger: 'blur' }
          ],
          remarks: [
            { required: true, message: '备注信息不能为空', trigger: 'blur' }
          ],
          reportWriter: [
            { required: true, message: '报告编写人不能为空', trigger: 'blur' }
          ],
          reportDate: [
            { required: true, message: '报告编写日期不能为空', trigger: 'blur' }
          ],
          reportChecker: [
            { required: true, message: '报告校核人不能为空', trigger: 'blur' }
          ],
          reportCheckerOpinion: [
            { required: true, message: '报告校核意见不能为空', trigger: 'blur' }
          ],
          reportCheckerDate: [
            { required: true, message: '报告校核日期不能为空', trigger: 'blur' }
          ],
          reportPath: [
            { required: true, message: '报告路径不能为空', trigger: 'blur' }
          ],
          pdfPath: [
            { required: true, message: 'pdf路径不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/reportApproval/report/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.productId = data.report.productId
                this.dataForm.productName = data.report.productName
                this.dataForm.producerName = data.report.producerName
                this.dataForm.sampleType = data.report.sampleType
                this.dataForm.registeredAddress = data.report.registeredAddress
                this.dataForm.sampleNum = data.report.sampleNum
                this.dataForm.manufactoryName = data.report.manufactoryName
                this.dataForm.sampleBernum = data.report.sampleBernum
                this.dataForm.registeredAddressSample = data.report.registeredAddressSample
                this.dataForm.productionDate = data.report.productionDate
                this.dataForm.sampleGrade = data.report.sampleGrade
                this.dataForm.sampleAcqMethod = data.report.sampleAcqMethod
                this.dataForm.samplingBasicNumber = data.report.samplingBasicNumber
                this.dataForm.samplingBasicDate = data.report.samplingBasicDate
                this.dataForm.samplingBasicPlace = data.report.samplingBasicPlace
                this.dataForm.arriveDate = data.report.arriveDate
                this.dataForm.provingTime = data.report.provingTime
                this.dataForm.checkGroundPoint = data.report.checkGroundPoint
                this.dataForm.mainTestingEquipment = data.report.mainTestingEquipment
                this.dataForm.checkAccording = data.report.checkAccording
                this.dataForm.checkConclusion = data.report.checkConclusion
                this.dataForm.issueDate = data.report.issueDate
                this.dataForm.remark = data.report.remark
                this.dataForm.reprotStatus = data.report.reprotStatus
                this.dataForm.approver = data.report.approver
                this.dataForm.approvalOpinion = data.report.approvalOpinion
                this.dataForm.auditor = data.report.auditor
                this.dataForm.auditOpinion = data.report.auditOpinion
                this.dataForm.dateOfApproval = data.report.dateOfApproval
                this.dataForm.projectLeader = data.report.projectLeader
                this.dataForm.projectLeaderOpinion = data.report.projectLeaderOpinion
                this.dataForm.projectLeaderDate = data.report.projectLeaderDate
                this.dataForm.pictureProductName = data.report.pictureProductName
                this.dataForm.pictureModel = data.report.pictureModel
                this.dataForm.remarks = data.report.remarks
                this.dataForm.reportWriter = data.report.reportWriter
                this.dataForm.reportDate = data.report.reportDate
                this.dataForm.reportChecker = data.report.reportChecker
                this.dataForm.reportCheckerOpinion = data.report.reportCheckerOpinion
                this.dataForm.reportCheckerDate = data.report.reportCheckerDate
                this.dataForm.reportPath = data.report.reportPath
                this.dataForm.pdfPath = data.report.pdfPath
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/reportApproval/report/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'productId': this.dataForm.productId,
                'productName': this.dataForm.productName,
                'producerName': this.dataForm.producerName,
                'sampleType': this.dataForm.sampleType,
                'registeredAddress': this.dataForm.registeredAddress,
                'sampleNum': this.dataForm.sampleNum,
                'manufactoryName': this.dataForm.manufactoryName,
                'sampleBernum': this.dataForm.sampleBernum,
                'registeredAddressSample': this.dataForm.registeredAddressSample,
                'productionDate': this.dataForm.productionDate,
                'sampleGrade': this.dataForm.sampleGrade,
                'sampleAcqMethod': this.dataForm.sampleAcqMethod,
                'samplingBasicNumber': this.dataForm.samplingBasicNumber,
                'samplingBasicDate': this.dataForm.samplingBasicDate,
                'samplingBasicPlace': this.dataForm.samplingBasicPlace,
                'arriveDate': this.dataForm.arriveDate,
                'provingTime': this.dataForm.provingTime,
                'checkGroundPoint': this.dataForm.checkGroundPoint,
                'mainTestingEquipment': this.dataForm.mainTestingEquipment,
                'checkAccording': this.dataForm.checkAccording,
                'checkConclusion': this.dataForm.checkConclusion,
                'issueDate': this.dataForm.issueDate,
                'remark': this.dataForm.remark,
                'reprotStatus': this.dataForm.reprotStatus,
                'approver': this.dataForm.approver,
                'approvalOpinion': this.dataForm.approvalOpinion,
                'auditor': this.dataForm.auditor,
                'auditOpinion': this.dataForm.auditOpinion,
                'dateOfApproval': this.dataForm.dateOfApproval,
                'projectLeader': this.dataForm.projectLeader,
                'projectLeaderOpinion': this.dataForm.projectLeaderOpinion,
                'projectLeaderDate': this.dataForm.projectLeaderDate,
                'pictureProductName': this.dataForm.pictureProductName,
                'pictureModel': this.dataForm.pictureModel,
                'remarks': this.dataForm.remarks,
                'reportWriter': this.dataForm.reportWriter,
                'reportDate': this.dataForm.reportDate,
                'reportChecker': this.dataForm.reportChecker,
                'reportCheckerOpinion': this.dataForm.reportCheckerOpinion,
                'reportCheckerDate': this.dataForm.reportCheckerDate,
                'reportPath': this.dataForm.reportPath,
                'pdfPath': this.dataForm.pdfPath
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
